import request from '@/utils/request'

// 用户登录
export function login(loginForm) {
  return request({
    url: '/user/login',
    method: 'post',
    data: loginForm
  })
}

// 用户注册
export function register(registerForm) {
  return request({
    url: '/user/register',
    method: 'post',
    data: registerForm
  })
}

// 获取用户信息
export function getUserInfo() {
  return request({
    url: '/user/info',
    method: 'get'
  })
}

// 更新用户信息
export function updateUserInfo(userInfo) {
  return request({
    url: '/user/info',
    method: 'put',
    data: userInfo
  })
}

// 修改密码
export function changePassword(passwordForm) {
  return request({
    url: '/user/password',
    method: 'put',
    data: passwordForm
  })
}

// 用户登出
export function logout() {
  return request({
    url: '/user/logout',
    method: 'post'
  })
}

// 获取用户列表（管理员功能）
export function getUserList(params) {
  return request({
    url: '/user/list',
    method: 'get',
    params: params
  })
}

// 启用/禁用用户
export function toggleUserStatus(userId, status) {
  return request({
    url: '/user/' + userId + '/status',
    method: 'put',
    data: { status }
  })
}

// 重置用户密码
export function resetPassword(userId) {
  return request({
    url: '/user/' + userId + '/reset-password',
    method: 'put'
  })
}

// 默认导出对象
const userAPI = {
  login,
  register,
  getUserInfo,
  updateUserInfo,
  changePassword,
  logout,
  getUserList,
  toggleUserStatus,
  resetPassword
}

export default userAPI